package com.burstly.lib.component.networkcomponent.burstly;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.media.MediaPlayer;
import com.burstly.lib.util.LoggerExt;

public class AudioControlReciever extends BroadcastReceiver
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final int MUTED_VOLUME = 0;
  private static final int NORMAL_VOLUME = 100;
  private static final String TAG = AudioControlReciever.class.getSimpleName();
  private AudioManager mAudioManager;
  private final Context mContext;
  private MediaPlayer mMediaPlayer;
  private boolean mRegistered;

  public AudioControlReciever(Context paramContext)
  {
    this.mContext = paramContext;
    this.mAudioManager = ((AudioManager)paramContext.getSystemService("audio"));
  }

  private void setVolume(int paramInt)
  {
    if (100 - paramInt > 0);
    for (double d = Math.log(100 - paramInt); ; d = 0.0D)
    {
      float f = (float)(1.0D - d / Math.log(100.0D));
      if (this.mMediaPlayer == null)
        break;
      this.mMediaPlayer.setVolume(f, f);
      return;
    }
    LOG.logDebug(TAG, "Can not set volume for MediaPlayer due it hasn't been set before.", new Object[0]);
  }

  public MediaPlayer getMediaPlayer()
  {
    return this.mMediaPlayer;
  }

  public void onReceive(Context paramContext, Intent paramIntent)
  {
    LOG.logDebug(TAG, "Ringer mode changed", new Object[0]);
    switch (this.mAudioManager.getRingerMode())
    {
    default:
      return;
    case 0:
    case 1:
      setVolume(0);
      return;
    case 2:
    }
    setVolume(100);
  }

  public void registerReciever()
  {
    if (!this.mRegistered)
    {
      this.mContext.registerReceiver(this, new IntentFilter("android.media.RINGER_MODE_CHANGED"));
      this.mRegistered = true;
    }
  }

  public void setMediaPlayer(MediaPlayer paramMediaPlayer)
  {
    this.mMediaPlayer = paramMediaPlayer;
  }

  public void unRegisterReciever()
  {
    if (this.mRegistered)
    {
      this.mContext.unregisterReceiver(this);
      this.mRegistered = false;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.AudioControlReciever
 * JD-Core Version:    0.6.2
 */